package com.jhgsys.internal.incentive.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.incentive.entity.IncentiveRewardClauseRuleRecord;
import com.jhgsys.internal.incentive.service.IIncentiveRewardClauseRuleRecordService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 奖励规则变更记录 Controller
 *
 * @author zjb
 * @date 2024-08-30 09:51:18
 */
@Slf4j
@Validated
@Controller
public class IncentiveRewardClauseRuleRecordController extends BaseController {

    @Autowired
    private IIncentiveRewardClauseRuleRecordService incentiveRewardClauseRuleRecordService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardClauseRuleRecord")
    @RequiresPermissions("incentiveRewardClauseRuleRecord:view")
    public String incentiveRewardClauseRuleRecordIndex(){
        return FebsUtil.view("incentive/incentiveRewardClauseRuleRecord/incentiveRewardClauseRuleRecordList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardClauseRuleRecord/add")
    @RequiresPermissions("incentiveRewardClauseRuleRecord:add")
    public String incentiveRewardClauseRuleRecordAdd(){
        return FebsUtil.view("incentive/incentiveRewardClauseRuleRecord/incentiveRewardClauseRuleRecordEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardClauseRuleRecord/update/{id}")
    @RequiresPermissions("incentiveRewardClauseRuleRecord:edit")
    public String incentiveRewardClauseRuleRecordUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("incentiveRewardClauseRuleRecord", incentiveRewardClauseRuleRecordService.findIncentiveRewardClauseRuleRecordById(id));
        return FebsUtil.view("incentive/incentiveRewardClauseRuleRecord/incentiveRewardClauseRuleRecordEdit");
    }

    /**
     * 查询（所有）
     * @author zjb
     * @date 2024-08-30 09:51:18
     */
    @GetMapping("incentiveRewardClauseRuleRecord")
    @ResponseBody
    @RequiresPermissions("incentiveRewardClauseRuleRecord:view")
    public FebsResponse getAllIncentiveRewardClauseRuleRecords(IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord) {
        return new FebsResponse().success().data(incentiveRewardClauseRuleRecordService.findIncentiveRewardClauseRuleRecordList(incentiveRewardClauseRuleRecord));
    }

    /**
     * 查询（分页）
     * @author zjb
     * @date 2024-08-30 09:51:18
     */
    @GetMapping("incentiveRewardClauseRuleRecord/list")
    @ResponseBody
    @RequiresPermissions("incentiveRewardClauseRuleRecord:view")
    public FebsResponse incentiveRewardClauseRuleRecordList(QueryRequest request, IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord) {
        Map<String, Object> dataTable = getDataTable(this.incentiveRewardClauseRuleRecordService.findIncentiveRewardClauseRuleRecordPage(request, incentiveRewardClauseRuleRecord));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 IncentiveRewardClauseRuleRecord
     * @author zjb
     * @date 2024-08-30 09:51:18
     */
    @Log("新增IncentiveRewardClauseRuleRecord")
    @PostMapping("incentiveRewardClauseRuleRecord")
    @ResponseBody
    @RequiresPermissions("incentiveRewardClauseRuleRecord:add")
    public FebsResponse addIncentiveRewardClauseRuleRecord(@Valid IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord) throws FebsException {
        try {
            incentiveRewardClauseRuleRecord.setCreatedBy(getCurrentUser().getUserName());
            this.incentiveRewardClauseRuleRecordService.createIncentiveRewardClauseRuleRecord(incentiveRewardClauseRuleRecord);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增IncentiveRewardClauseRuleRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 逻辑删除 IncentiveRewardClauseRuleRecord
     * @author zjb
     * @date 2024-08-30 09:51:18
     */
    @Log("逻辑删除IncentiveRewardClauseRuleRecord")
    @GetMapping("incentiveRewardClauseRuleRecord/delete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardClauseRuleRecord:delete")
    public FebsResponse deleteIncentiveRewardClauseRuleRecord(@PathVariable("id") String incentiveRewardClauseRuleRecordIds) throws FebsException {
        try {
            IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord = new IncentiveRewardClauseRuleRecord();
            incentiveRewardClauseRuleRecord.setDeletedBy(getCurrentUser().getUserName());
            incentiveRewardClauseRuleRecord.setDeletedTime(new Date());
            incentiveRewardClauseRuleRecord.setDeletedFlg(FebsConstant.INVALID);
            this.incentiveRewardClauseRuleRecordService.deleteIncentiveRewardClauseRuleRecord(incentiveRewardClauseRuleRecord,incentiveRewardClauseRuleRecordIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardClauseRuleRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
    * 物理删除 IncentiveRewardClauseRuleRecord
    * @author zjb
    * @date 2024-08-30 09:51:18
    */
    @Log("物理删除IncentiveRewardClauseRuleRecord")
    @GetMapping("incentiveRewardClauseRuleRecord/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardClauseRuleRecord:delete")
    public FebsResponse physicallyDeleteIncentiveRewardClauseRuleRecord(@PathVariable("id") String incentiveRewardClauseRuleRecordIds) throws FebsException {
        try {
            this.incentiveRewardClauseRuleRecordService.physicallyDeleteIncentiveRewardClauseRuleRecord(incentiveRewardClauseRuleRecordIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardClauseRuleRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 修改 IncentiveRewardClauseRuleRecord
     * @author zjb
     * @date 2024-08-30 09:51:18
     */
    @Log("修改IncentiveRewardClauseRuleRecord")
    @PostMapping("incentiveRewardClauseRuleRecord/update")
    @ResponseBody
    @RequiresPermissions("incentiveRewardClauseRuleRecord:edit")
    public FebsResponse updateIncentiveRewardClauseRuleRecord(IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord) throws FebsException {
        try {
            incentiveRewardClauseRuleRecord.setUpdatedBy(getCurrentUser().getUserName());
            this.incentiveRewardClauseRuleRecordService.updateIncentiveRewardClauseRuleRecord(incentiveRewardClauseRuleRecord);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改IncentiveRewardClauseRuleRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

}
